﻿namespace HuwmanCode

open System

[<RequireQualifiedAccess>]
module Option =
    /// <summary>
    /// Converts a 't option option to a 't option.
    /// </summary>
    let peel (value:'t option option) =
        match value with
        | Some v -> v
        | None -> None

    /// <summary>
    /// Returns value of option or default value.
    /// </summary>
    let defaultTo defaultValue opt =
        match opt with
        | Some opt -> opt
        | None -> defaultValue

    /// <summary>
    /// Maps a 't option to 'm 
    /// </summary>
    let mapOrDefault2 (mf:'t->'m) defaultValue opt =
        match opt with
        | Some opt -> mf opt
        | None -> defaultValue

    /// <summary>
    /// Maps a 't option to 'm 
    /// </summary>
    let mapOrDefault  (mf:'t->'m) opt =
        opt |> mapOrDefault2  mf Unchecked.defaultof<_>